<%@ page language="java" %>
<%
    response.setHeader("Cache-Control", "no-cache");
    response.setHeader("Pragma", "no-cache");
    response.setDateHeader("max-age", 0);
    response.setDateHeader("Expires", 0);
%>

<%@ page import="java.util.ArrayList,
                java.util.HashMap,java.util.Enumeration,
                com.scalar.chiptrack.operations.packingslip.CustomerShippingLotNumberData,
                com.scalar.chiptrack.operations.packingslip.FinalInventoryData,
                com.scalar.chiptrack.utils.ConfigManager,
                com.scalar.chiptrack.utils.StringUtils,
                com.scalar.chiptrack.commons.Constants,
                com.scalar.chiptrack.commons.SessionKeys,
                com.scalar.chiptrack.users.User,
                com.scalar.chiptrack.users.Functionality"%>
<%@ page import="com.scalar.chiptrack.utils.WorkWeek" %>
<%@ page import="org.apache.struts.util.LabelValueBean" %>

<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/chiptrack-tags.tld" prefix="chiptrack" %>

<%
    String closeWindowAfterSessionTimeOut = ( String ) request.getAttribute( "closeWindowAfterSessionExp" );
    if ( closeWindowAfterSessionTimeOut == null )
    {
%>
    <chiptrack:checkLogon sourcePage="/packingSlip.do"/>
<% } %>

<%String chipTracContext = "/" + ConfigManager.getChipTracContext();%>

<% User user1 = (User)session.getAttribute (SessionKeys.USER_KEY); %>
<%
	String txtIndex						= request.getParameter("index");
	ArrayList finalInventoryDataList	= (ArrayList) session.getAttribute ( "finalInventoryDataList" );

	String quantityToBeShipped			= (String)request.getParameter( "quantityToBeShipped" );
    boolean issuedPackingSlip			= Boolean.valueOf ( request.getParameter( "issedPackingSlip" ) ).booleanValue();
    String errMsg						= " ";
    boolean viewOnly					= Boolean.valueOf ( ( String ) request.getAttribute( "viewOnly" ) ).booleanValue();

    HashMap requestedQuantityMap		= (HashMap)session.getValue( "requestedQuantity" );
    String  requestedQuantity			= "0";

	String closeWindowAfterSave			= (String)request.getAttribute( "closeWindow" );

	if ( requestedQuantityMap != null )
    {
        String index = request.getParameter("fieldName").substring(16,17);
        requestedQuantity = (String)requestedQuantityMap.get(index);
    }
%>

<html:html locale="true">

<HEAD>
	<TITLE>Scalarsoft - ChipTrac</TITLE>
<META http-equiv=Content-Type content="text/html; charset=windows-1252">
<LINK href="<%=chipTracContext%>/jsp/includes/stylesheets/scalarsoft.css" type="text/css" rel="stylesheet">
<SCRIPT language="JavaScript" src="<%=chipTracContext%>/jsp/includes/scripts/validations.js"></SCRIPT>
</HEAD>

<SCRIPT language="JavaScript">

<%
if ( ( closeWindowAfterSave != null ) && ( closeWindowAfterSave.equalsIgnoreCase( "true" ) ) ) {
%>
	window.close();
<%}%>

function openAudit (lotNumber,lotId)
{
    var finalInventoryURL = '<%=chipTracContext%>/jsp/operations/lot_qty_pull_audit.jsp?lotId='+lotId+'&lotNumber=' + lotNumber;
    newWindow = window.open (finalInventoryURL,'lotAudit','channelmode=no,directories=no,toolbar=no,menubar=no,personalbar=no,status=no,scrollbars=yes,width=700,height=300,resizable=yes');
    newWindow.focus();
}

function calcDynValues()
{
	//alert("calcDynValues");
    calcBalance();
	//alert("calcQtyToBeShipped");
    calcQtyToBeShipped();
}


var firstTimeCalcBalance = true;
var qtyPulled			 = new Array();

function calcBalance()
{
	// This condition is added by ravikanth on 08-05-2004
	// Because in drop shipment there can be a condition where there are no lots for the PartNumber
	if( typeof document.finalInventoryForm.quantityToPull != 'undefined'  )
	{
		if ( document.finalInventoryForm.quantityToPull.length == null )
		{
			if ( firstTimeCalcBalance )
			{
				if ( document.finalInventoryForm.quantityToPull.value.length != 0 )
				{
					qtyPulled[0] = document.finalInventoryForm.quantityToPull.value;
				}
				else
				{
					qtyPulled[0] = 0;
				}

				if( !isNaN( parseInt( document.finalInventoryForm.initBalances.value ) ) )
				{
					document.finalInventoryForm.balance.value = document.finalInventoryForm.initBalances.value
				}
				firstTimeCalcBalance = false;
			}
			else
			{
				if ( document.finalInventoryForm.quantityToPull.value.length != 0 )
				{
					if( !isNaN( parseInt( document.finalInventoryForm.initBalances.value ) ) && !isNaN( parseInt( document.finalInventoryForm.quantityToPull.value ) ) && !isNaN( parseInt( qtyPulled[0] ) ) )
					{
						document.finalInventoryForm.balance.value = ( parseInt( document.finalInventoryForm.initBalances.value ) - parseInt( document.finalInventoryForm.quantityToPull.value ) + parseInt( qtyPulled[0] ) );
					}
				}
				else
				{
					if( document.finalInventoryForm.actualCsLineItemId.value == -1 )
					{
						if( !isNaN( parseInt( document.finalInventoryForm.initBalances.value ) ) && !isNaN( parseInt( qtyPulled[0] ) ) )
						{
							document.finalInventoryForm.balance.value = parseInt( document.finalInventoryForm.initBalances.value ) + parseInt( qtyPulled[0] );
						}
					}
					else
					{
						if( !isNaN( parseInt( document.finalInventoryForm.initBalances.value ) ) )
						{
							document.finalInventoryForm.balance.value = parseInt( document.finalInventoryForm.initBalances.value );
						}
					}

					var hiddenQtyPull = document.finalInventoryForm.quantityToPullHidden.value.trim();

					if ( ( hiddenQtyPull.length != null ) && ( !isNaN ( parseInt (hiddenQtyPull ) ) ) )
					{
						if( !isNaN( parseInt( document.finalInventoryForm.initBalances.value ) ) && !isNaN( parseInt( hiddenQtyPull ) ) )
						{
							document.finalInventoryForm.balance.value = parseInt( document.finalInventoryForm.initBalances.value ) + parseInt( hiddenQtyPull );
						}
					}
				}
			}
		}
		else
		{
			for ( var i=0; i < document.finalInventoryForm.quantityToPull.length; i++ )
			{
				if ( firstTimeCalcBalance )
				{
					if ( document.finalInventoryForm.quantityToPull[i].value.length != 0 )
					{
						qtyPulled[i] = document.finalInventoryForm.quantityToPull[i].value;
					}
					else
					{
						qtyPulled[i] = 0;
					}

					document.finalInventoryForm.balance[i].value = document.finalInventoryForm.initBalances[i].value;
				}
				else
				{
					if ( document.finalInventoryForm.quantityToPull[i].value.length != 0 )
					{
						// this condition is added By Ravikanth on 04-05-2004
						// needs to checked when the Lot is completly drawn
						if( document.finalInventoryForm.initBalances[i].value.length != 0 )
						{
							document.finalInventoryForm.balance[i].value = ( parseInt( document.finalInventoryForm.initBalances[i].value ) -
																		 parseInt( document.finalInventoryForm.quantityToPull[i].value ) + parseInt( qtyPulled[i] ) );
						}
					}
					else
					{
						if( document.finalInventoryForm.actualCsLineItemId.value == -1 )
						{
							// this condition is added By Ravikanth on 04-05-2004
							if( !isNaN( parseInt( document.finalInventoryForm.initBalances[i].value)) && !isNaN( parseInt( qtyPulled[i] ) ) )
							{
								document.finalInventoryForm.balance[i].value = parseInt( document.finalInventoryForm.initBalances[i].value ) + parseInt( qtyPulled[i] );
							}
						}
						else
						{
							// this condition is added By Ravikanth on 04-05-2004
							if( !isNaN ( parseInt( document.finalInventoryForm.initBalances[i].value ) ) )
							{
								document.finalInventoryForm.balance[i].value = parseInt( document.finalInventoryForm.initBalances[i].value );
							}
						}
						var hiddenQtyPull = document.finalInventoryForm.quantityToPullHidden[i].value.trim();
						if ( ( hiddenQtyPull.length != null ) && ( !isNaN ( parseInt (hiddenQtyPull ) ) ) )
						{
							// this condition is added By Ravikanth on 04-05-2004
							if( !isNaN( parseInt( document.finalInventoryForm.initBalances[i].value )) && !isNaN( parseInt( hiddenQtyPull )))
							{
								document.finalInventoryForm.balance[i].value = parseInt( document.finalInventoryForm.initBalances[i].value ) + parseInt( hiddenQtyPull );
							}
						}
					}
				}
			}

			if ( firstTimeCalcBalance )
			{
				firstTimeCalcBalance = false;
			}
		}
	}
}

var initTotalQtyPulled;
var initQtyToBeShipped;
var firstTimeCalcQty = true;
var requestedQty;

function calcQtyToBeShipped()
{
	// This condition is added by ravikanth on 08-05-2004
	// Because in drop shipment there can be a condition where there are no lots for the PartNumber
	if( typeof document.finalInventoryForm.quantityToPull != 'undefined'  )
	{

		if ( document.finalInventoryForm.quantityToPull.length == null )
		{

			var sum = 0;
			if ( document.finalInventoryForm.quantityToPull.value.length != 0 )
			{
				sum = document.finalInventoryForm.quantityToPull.value;
			}
			if( firstTimeCalcQty == true )
			{
				if( document.finalInventoryForm.actualCsLineItemId.value == -1 )
				{
					requestedQty = parseInt('<%=quantityToBeShipped%>');
				}
				else
				{
					// Condition added By Ravikanth on 05-05-2004
					if( document.finalInventoryForm.dropShip.value == 'true' )
					{
						requestedQty = parseInt('<%=quantityToBeShipped%>');
					}
					else
					{
						requestedQty = parseInt( parseInt('<%=quantityToBeShipped%>') + parseInt(sum) );
					}
				}
				initQtyToBeShipped = ( requestedQty - sum );
				initTotalQtyPulled = sum;

				firstTimeCalcQty = false;
			}

			document.finalInventoryForm.qtyTobeShipped.value = requestedQty - sum ;
		}
		else
		{
			var sum = 0;
			for( var i=0; i < document.finalInventoryForm.quantityToPull.length; i++ )
			{
				if ( document.finalInventoryForm.quantityToPull[i].value.length != 0 )
				{
					sum += parseInt ( document.finalInventoryForm.quantityToPull[i].value );
				}
			}

			if( firstTimeCalcQty == true )
			{
				if( document.finalInventoryForm.actualCsLineItemId.value == -1 )
				{
					requestedQty = parseInt('<%=quantityToBeShipped%>');
				}
				else
				{
					// Condition added By Ravikanth on 05-05-2004
					if( document.finalInventoryForm.dropShip.value == 'true' )
					{
						requestedQty = parseInt('<%=quantityToBeShipped%>');
					}
					else
					{
						requestedQty = parseInt('<%=quantityToBeShipped%>') + parseInt( sum );
					}
				}

				initQtyToBeShipped = (requestedQty - sum);
				initTotalQtyPulled = sum;

				firstTimeCalcQty = false;
			}

			document.finalInventoryForm.qtyTobeShipped.value = (requestedQty - sum);
		}
	}
	else
	{
		var sum = 0;
		requestedQty = parseInt('<%=quantityToBeShipped%>');
		initQtyToBeShipped = (requestedQty - sum);
		initTotalQtyPulled = sum;
		firstTimeCalcQty = false;
		document.finalInventoryForm.qtyTobeShipped.value = (requestedQty - sum);
	}

}

/*
	There is a gamble in this function, we are setting the locationId to shippingFromAddressId
	value as we are not having the LocationId parameter for new Lots.
*/

function addMore( partNumber, locationId, csLineItemId )
{
	var htmlText;
	var pa=document.getElementById("font1");
	var index = parseInt( document.finalInventoryForm.noOfLots.value );
	htmlText = '<table><tr><td align="center" nowrap width="25%"><font class="NArialL">';
	htmlText = htmlText + partNumber;
	htmlText = htmlText + '</font></td>';
	htmlText = htmlText + '<input type="hidden" name="mktPartNumber" value="' + partNumber +'">';
	htmlText = htmlText + '<input type="hidden" name="locationId" value="' + locationId + '">';
	htmlText = htmlText + '<td align="center" nowrap width="15%">'
	htmlText = htmlText + '<font class="NArialL"><input type="text" name="lotNumber" size="13" maxLength="50" value="" class="valuetxfield" >';
	htmlText = htmlText + '<input type="hidden" name="lotId" value="-1">';
    <%if( ConfigManager.getShowFabLotNumberInPackingSlip() )
    { %>
    htmlText = htmlText + '<font class="NArialL"><input type="text" name="fabLotNumber" size="13" maxLength="50" value="" class="valuetxfield" >';
    <%} else
    {%>
    htmltext = '<input type="hidden" name="fabLotNumber" value="">'
     <%}%>
    htmlText = htmlText + '<td align="center" nowrap width="15%"><input type="text" name="dateCode" maxLength="10" size="13" value="" class="valuetxfield" ></td>';
	htmlText = htmlText + '<td align="right" nowrap width="15%"><input type="text" name="dateIn" maxLength="10" size="13" value="" class="valuetxfield" ></td>';
	htmlText = htmlText + '<td align="right" nowrap width="10%"><input type="text" name="hdnQuantityIn" size="8" maxLength="10" value="" class="valuetxfield" onkeypress="javascript:numericFieldKeyPress( this )" onblur="setQuantyties('+ index +')">';
	htmlText = htmlText + '</td>';
	htmlText = htmlText + '<td align="right" nowrap width="10%"><font class="NArialL">';
	htmlText = htmlText + '<input type="hidden" name=initBalances value="" >';
	htmlText = htmlText + '<input type="text" size="6" align=right name="balance" class="valuetxfield" style="BORDER-BOTTOM: thin; BORDER-LEFT-STYLE: none; BORDER-RIGHT-STYLE: none; BORDER-TOP: thin; CLEAR: none; COLOR: red;font-family: arial;font-size: 10pt;font-weight:bold " readOnly disabled value=""></td>';
	htmlText = htmlText + '<td align="center" nowrap width="15%"><font class="NArialL">';
	htmlText = htmlText + '<input type="text" size="13" nowrap name="quantityToPull" onkeypress="javascript:numericFieldKeyPress( this )" onkeyup="addQuantity(' + index + ')" value="" class="valuetxfield"></font>';
	htmlText = htmlText + '<input type="hidden" name="quantityToPullHidden" value="0" >';
	htmlText = htmlText + '<input type="hidden" name="csLineItemId" value="'+ csLineItemId +'">';
	htmlText = htmlText + '</td></tr></table>';
	document.finalInventoryForm.noOfLots.value = index + 1;
    pa.insertAdjacentHTML( 'BeforeEnd', htmlText );
}

function setQuantyties( index )
{
	var form	= document.finalInventoryForm;
	var qtyInObject;
	var qtyPullObject;
	var hdnQuantityInObject;
	var initBalancesObject;
	var quantityToPullObject;
	var quantityToPullHiddenObject;

	var qtyIn;
	var qtyPull;

	if( typeof form.hdnQuantityIn.length == 'undefined' )
	{
		qtyInObject = form.hdnQuantityIn;
		qtyPullObject = form.quantityToPull;
		hdnQuantityInObject = form.hdnQuantityIn;
		initBalancesObject	= form.initBalances;
		quantityToPullHiddenObject = form.quantityToPullHidden;
	}
	else
	{
		qtyInObject = form.hdnQuantityIn[ index ];
		qtyPullObject = form.quantityToPull[ index ];
		hdnQuantityInObject = form.hdnQuantityIn[ index ];
		initBalancesObject	= form.initBalances[ index ];
		quantityToPullHiddenObject = form.quantityToPullHidden[ index ];
	}

	qtyIn	= qtyInObject.value;
	qtyPull = qtyPullObject.value;

	if( qtyIn.length > 0 && isNaN ( parseInt( qtyIn ) ) )
	{
		hdnQuantityInObject.value = "";
		hdnQuantityInObject.focus();
	}
	else if( qtyIn < qtyPull )
	{
		form.initBalances[ index ].value = 0;
		form.quantityToPull[ index ].value = 0;
		calcBalance();
	}
	else
	{
		initBalancesObject.value = parseInt( qtyIn );
		//form.initBalances[ index ].value = parseInt( qtyIn );
		//form.quantityToPullHidden[ index ].value = 0;
		quantityToPullHiddenObject.value = 0;
		if ( document.finalInventoryForm.quantityToPull.length == null )
		{
			qtyPulled[0] = 0;
		}
		else
		{
			qtyPulled[index] = 0;
			for ( var i = 0; i < document.finalInventoryForm.quantityToPull.length; i++ )
			{
				if ( qtyPulled[i] != 0 )
				{
					qtyPulled[i] = qtyPulled[i];
				}
				else
				{
					qtyPulled[i] = 0;
				}
			}
		}
		calcBalance();
	}
}

function resetValues()
{
    if (document.finalInventoryForm.quantityToPull.length == null)
    {
        document.finalInventoryForm.quantityToPull.value = qtyPulled[0];
    }
    else
    {
        for( var i=0; i < document.finalInventoryForm.quantityToPull.length; i++ )
        {
            if ( qtyPulled[i] <= 0 )
            {
                document.finalInventoryForm.quantityToPull[i].value = "";
            }
            else
            {
                document.finalInventoryForm.quantityToPull[i].value = qtyPulled[i];
            }
            document.finalInventoryForm.balance[i].value = document.finalInventoryForm.initBalances[i].value;
        }
    }
    document.finalInventoryForm.qtyTobeShipped.value = initQtyToBeShipped;
    document.finalInventoryForm.totals.value = initTotalQtyPulled;
}

function addQuantity( lotIndex )
{
    document.finalInventoryForm.txtErrMsg.value = "";

    var maxQtyToPull = 0;
    var sum = 0;
    var index = 0;

    if (document.finalInventoryForm.quantityToPull.length == null)
    {
        if (document.finalInventoryForm.initBalances.value < 0)
        {
            maxQtyToPull = qtyPulled[0];
        }
        else
        {
            maxQtyToPull = parseInt( document.finalInventoryForm.initBalances.value ) + parseInt( qtyPulled[0] );
        }

		if( !isNaN ( parseInt( document.finalInventoryForm.quantityToPull.value ) ) )
		{
			if( parseInt( document.finalInventoryForm.quantityToPull.value ) <= maxQtyToPull )
			{
				sum = parseInt ( document.finalInventoryForm.quantityToPull.value );
			}
			else
			{
				document.finalInventoryForm.txtErrMsg.value='Quantity should be less than or equal to balance';
				document.finalInventoryForm.quantityToPull.value="";
			}
		}
    }
    else
    {
        for ( var i=0; i < document.finalInventoryForm.quantityToPull.length; i++ )
        {
            if ( document.finalInventoryForm.quantityToPull[i].value.length != 0 )
            {
                if ( document.finalInventoryForm.initBalances[i].value < 0 )
                {
                    maxQtyToPull = qtyPulled[i];
                }
                else
                {
                    maxQtyToPull = parseInt( document.finalInventoryForm.initBalances[i].value ) + parseInt( qtyPulled[i] );
                }

				if( !isNaN ( parseInt( document.finalInventoryForm.quantityToPull[i].value ) ) )
				{
					if( parseInt( document.finalInventoryForm.quantityToPull[i].value ) <= maxQtyToPull )
					{
						sum += parseInt ( document.finalInventoryForm.quantityToPull[i].value );
						index=i;
					}
					else
					{
						document.finalInventoryForm.txtErrMsg.value='Quantity should be less than or equal to balance';
						document.finalInventoryForm.quantityToPull[i].value="";
						index=i;
					}
				}
            }
        }
    }
	var tempTotal = document.finalInventoryForm.totals.value;
	document.finalInventoryForm.totals.value = sum;

    if ( parseInt( requestedQty ) < parseInt( sum ) )
    {
        if ( document.finalInventoryForm.quantityToPull.length == null )
        {
            document.finalInventoryForm.quantityToPull.value = tempTotal;
            document.finalInventoryForm.totals.value = tempTotal;
        }
		else
		{
			var faultyQtyToPull = 0;
			for (var counts = 0; counts < document.finalInventoryForm.quantityToPull.length; counts++ )
			{
				if ( (document.finalInventoryForm.quantityToPull[counts].value.length != 0 ) && ( counts != lotIndex ) )
				{
					faultyQtyToPull += parseInt(document.finalInventoryForm.quantityToPull[counts].value);
				}
			}
			faultyQtyToPull = parseInt (tempTotal) - parseInt (faultyQtyToPull );
            document.finalInventoryForm.quantityToPull[lotIndex].value = faultyQtyToPull;
			document.finalInventoryForm.totals.value=tempTotal;
        }
        document.finalInventoryForm.txtErrMsg.value='Total should be less than or equal to Quantity to be shipped';
    }

    else
    {
        calcDynValues();
    }
}


function saveData() {

    document.finalInventoryForm.txtErrMsg.value = "";
	var index = <%=txtIndex%>;
    var sum = 0;
    var flag = 0;
	var msg = '';

    var partNumberV = "" ;

	if ( document.finalInventoryForm.quantityToPull != null )
	{           
		if( document.finalInventoryForm.dropShip.value == 'true' )
		{
			trimValues();
			// Check For Duplicate LotNumbers
			msg = checkForDulicateLotNumbers();

			if( msg.length == 0 )
			{
				// Check if LotNumber is given for every New Lot where the Quantity is Pulled
				msg = checkForEmptyLotNumbers();
			}

			if( msg.length == 0 )
			{
				// Check if LotNumber is given for every New Lot where the Quantity is Pulled
				msg = checkForValidDate();
			}

			if( msg.length > 0 )
			{
				document.finalInventoryForm.txtErrMsg.value = msg;
				return;
			}
		}

		if ( document.finalInventoryForm.quantityToPull.length == null )
		{
			if( checkInteger( document.finalInventoryForm.quantityToPull.value,"Quantity Pull","N" ) == false )
			{
				 document.finalInventoryForm.txtErrMsg.value=errMsg;
				 document.finalInventoryForm.quantityToPull.focus();
				 flag=1;
			}
			else
			{
				sum = document.finalInventoryForm.quantityToPull.value.trim();

				if( sum.length == 0 )
				{
					sum = 0;
				}

				var fieldValue  =  window.opener.document.packingSlipForm[ 'lineitems[' + index +'].qtyPulled'];
                var fieldValue1 =  window.opener.document.packingSlipForm[ 'lineitems[' + index +'].inventoryPulled'];
				/*if( window.opener.document.packingSlipForm.inventoryPulled.length == null  )
				{
					var fieldValue1 =  window.opener.document.packingSlipForm.inventoryPulled;
				}
				else
				{
					var fieldValue1 =  window.opener.document.packingSlipForm.inventoryPulled[ index ];
				}*/

				fieldValue.value  = sum;	// This sets the value for the Quantity Pulled
				fieldValue1.value = sum;	// This sets the value for the Inventory Pulled.
											// This is required for DropShipment To check wether the Qty is pulled from Inventory Screen

				if( parseInt( requestedQty ) < parseInt( document.finalInventoryForm.totals.value ) )
				{
					document.finalInventoryForm.txtErrMsg.value='Total should be less than or equal to Quantity to be shipped';
				}
				else
				{
					document.finalInventoryForm.balance.disabled = false;
					document.finalInventoryForm.totals.disabled = false;
					document.finalInventoryForm.qtyTobeShipped.disabled = false;
                    addOptionElementForParentWindow(index);
					document.finalInventoryForm.submit();
				}
			}
		}
		else
		{
			for( var i=0; i < document.finalInventoryForm.quantityToPull.length; i++ )
			{
				if (document.finalInventoryForm.quantityToPull[i].value.length != 0)
				{
					if(checkInteger(document.finalInventoryForm.quantityToPull[i].value,"Quantity Pull","N")==false)
					{
						 document.finalInventoryForm.txtErrMsg.value=errMsg;
						 document.finalInventoryForm.quantityToPull[i].focus();
						 flag=1;
						 break;
					}
					else
					{
						if (document.finalInventoryForm.quantityToPull[i].value.length != 0)
						{
							sum += parseInt (document.finalInventoryForm.quantityToPull[i].value.trim());
						}
					}
                    if ( document.finalInventoryForm.dateCode[i].value =='0')
                    {
                       if ( document.finalInventoryForm.dateCode1[i].value == '' )
                       {
                           document.finalInventoryForm.txtErrMsg.value= "Please enter new Date Code";
                           document.finalInventoryForm.dateCode1[i].focus();
                           return;
                       }

                   }
                   if ( document.finalInventoryForm.dateCode[i].value =='-1')
                   {
                       document.finalInventoryForm.txtErrMsg.value="Please select Date Code";
                       document.finalInventoryForm.dateCode[i].focus();
                       return;
                   }
				}

			}
			if(flag==0)
			{
				if( sum.length == 0 )
				{
					sum = 0;
				}
				var fieldValue =  window.opener.document.packingSlipForm[ 'lineitems[' + index +'].qtyPulled'];
                var fieldValue1 =  window.opener.document.packingSlipForm[ 'lineitems[' + index +'].inventoryPulled'];
				/*if( window.opener.document.packingSlipForm.inventoryPulled.length == null  )
				{
					var fieldValue1 =  window.opener.document.packingSlipForm.inventoryPulled;
				}
				else
				{
					var fieldValue1 =  window.opener.document.packingSlipForm.inventoryPulled[ index ];
				}*/

				//var fieldValue1 =  window.opener.document.packingSlipForm.inventoryPulled[ index ];
				//alert( fieldValue );
				//alert( fieldValue1 );
				fieldValue.value  = sum;
				fieldValue1.value = sum;
				//alert(window.opener.document.packingSlipForm.inventoryPulled[ index ].value);

				if( parseInt( requestedQty ) < parseInt( document.finalInventoryForm.totals.value ) )
				{
					document.finalInventoryForm.txtErrMsg.value='Total should be less than or equal to Quantity to be shipped';
				}
				else
				{
					for( var i=0; i < document.finalInventoryForm.quantityToPull.length; i++ )
					{
						document.finalInventoryForm.balance[i].disabled = false;
					}

					document.finalInventoryForm.totals.disabled = false;
					document.finalInventoryForm.qtyTobeShipped.disabled = false;
                    addOptionElementForParentWindow(index);
					document.finalInventoryForm.submit();
				}
			}
		}
	}
	else
	{
		window.close();
	}
}

function trimValues()
{
	form = document.finalInventoryForm;
	if( typeof form.lotId.length == 'undefined' )
	{
		form.lotNumber.value = form.lotNumber.value.trim();
		form.dateIn.value = form.dateIn.value.trim();
		form.dateCode.value = form.dateCode.value.trim();
	}
	else
	{
		for( var i = 0; i < form.lotId.length; i++ )
		{
			if( form.lotId[i].value == -1 )
			{
				form.lotNumber[i].value	= form.lotNumber[i].value.trim();
				form.dateIn[i].value	= form.dateIn[i].value.trim();
				form.dateCode[i].value	= form.dateCode[i].value.trim();
			}
		}
	}
}

function checkForDulicateLotNumbers()
{
	form = document.finalInventoryForm;
	msg = "";

	if( typeof form.lotNumber.length == 'undefined' )
	{
	}
	else
	{
		lotNumbers = new Array( parseInt( form.noOfLots.value ) );
		for( var i = 0; i < parseInt( form.noOfLots.value ); i++ )
		{
			lotNumbers[i] = form.lotNumber[i].value;
		}

		for( var i = 0; i < lotNumbers.length - 1; i++ )
		{
			for( var j = i + 1; j < lotNumbers.length; j++ )
			{
				if( lotNumbers[i].length > 0 && lotNumbers[j].length > 0 )
				{
					if( lotNumbers[i] == lotNumbers[j] )
					{
						msg = msg + ' '+ lotNumbers[i];
					}
				}
			}
		}
	}

	if( msg.length > 0 )
	{
		msg = 'Duplicate LotNumbers cannot be entered '+ msg;
	}
	return msg;
}

function checkForEmptyLotNumbers()
{
	form = document.finalInventoryForm;
	msg = "";

    if( typeof form.lotNumber.length == 'undefined' )
	{
		//form.lotNumber.value = form.lotNumber.value.trim();
		if( ( ( form.quantityToPull.value.length > 0 && form.quantityToPull.value != '0' ) || ( form.hdnQuantityIn.value.length > 0 && form.hdnQuantityIn.value != '0' ) ) && form.lotNumber.value.length < 1 )
		{
			form.lotNumber.focus();
			msg = 'Lot Number cannot be Empty';
		}
	}
	else
	{
		for( var i = 0; i < form.lotNumber.length; i++ )
		{
			//form.lotNumber[i].value = form.lotNumber[i].value.trim();
			if( ( ( form.quantityToPull[i].value.length > 0 && form.quantityToPull[i].value != '0' ) || ( form.hdnQuantityIn[i].value.length > 0 && form.hdnQuantityIn[i].value != '0' ) ) && form.lotNumber[i].value.length < 1 )
			{
				form.lotNumber[i].focus();
				msg = 'Lot Number cannot be empty';
				break;
			}
		}
	}
	return msg;
}

function checkForValidDate()
{
	msg = "";

	if( typeof document.finalInventoryForm.dateIn.length == 'undefined' )
	{
		if( ( ( document.finalInventoryForm.quantityToPull.value.length > 0 && document.finalInventoryForm.quantityToPull.value != '0' ) || ( document.finalInventoryForm.hdnQuantityIn.value.length > 0 && document.finalInventoryForm.hdnQuantityIn.value != '0' ) )&& document.finalInventoryForm.dateIn.value.length > 0   && document.finalInventoryForm.lotId.value == -1 )
		{
			//document.finalInventoryForm.dateIn.value = document.finalInventoryForm.dateIn.value.trim();
			if( chkDate( document.finalInventoryForm.dateIn.value, "Date In", "Y" ) == false )
			{
				document.finalInventoryForm.dateIn.focus();
				msg = 'Please enter a valid Date for Date In';
			}
		}
	}
	else
	{
		for( var i = 0; i < document.finalInventoryForm.dateIn.length; i++ )
		{
			if( ( ( document.finalInventoryForm.quantityToPull[i].value.length > 0 && document.finalInventoryForm.quantityToPull[i].value != '0' ) || ( document.finalInventoryForm.hdnQuantityIn[i].value.length > 0 && document.finalInventoryForm.hdnQuantityIn[i].value != '0' ) )&& document.finalInventoryForm.dateIn[i].value.length > 0   && document.finalInventoryForm.lotId[i].value == -1 )
			{
				//document.finalInventoryForm.dateIn[i].value = document.finalInventoryForm.dateIn[i].value.trim();
				if( chkDate( document.finalInventoryForm.dateIn[i].value, "Date In", "Y" ) == false )
				{
					document.finalInventoryForm.dateIn[i].focus();
					msg = 'Please enter a valid Date for Date In';
					break;
				}
			}
		}
	}
	return msg;
}

function holdLotInfo()
{
    document.finalInventoryForm.txtErrMsg.value = "This Lot is on Hold, cannot modified the quantity pulled";
}
function clearHoldLotInfo()
{
    document.finalInventoryForm.txtErrMsg.value = "";
}
function addOptionElementForParentWindow( index )
{

    var partNumberV = "" ;
    var shippedPartNumberObj  =  window.opener.document.packingSlipForm[ 'lineitems[' + index +'].shipped_Part_Number'];
    var inventoryPulled = false;

    if (typeof document.finalInventoryForm.quantityToPull.length == "undefined" )
    {
        if (document.finalInventoryForm.quantityToPull.value.length != 0)
        {
            partNumberV = document.finalInventoryForm.mktPartNumber.value;
            if( parseInt( document.finalInventoryForm.quantityToPull.value ) > 0 )
            {
                //window.opener.deleteAllOptions (index);
                //window.opener.addOptionToSelect ( partNumberV , partNumberV , index );
                inventoryPulled = true;
            }
        }
    }
    else
    {
        if (document.finalInventoryForm.quantityToPull.length > 0)
        {
            //window.opener.deleteAllOptions(index);
        }
        for( var i=0; i < document.finalInventoryForm.quantityToPull.length; i++ )
        {
            if (document.finalInventoryForm.quantityToPull[i].value.length != 0)
            {
                partNumberV = document.finalInventoryForm.mktPartNumber[i].value;
                //alert ( index + " : partNumberV : " + partNumberV );
                if( parseInt( document.finalInventoryForm.quantityToPull[i].value ) > 0 )
                {
                    //window.opener.addOptionToSelect ( partNumberV , partNumberV , index );
                    //shippedPartNumberObj.disabled = true;
                    inventoryPulled = true;
                }
            }
        }
    }

    if(inventoryPulled)
        shippedPartNumberObj.disabled = true;
    else
        shippedPartNumberObj.disabled = false;

    //window.opener.chjIndexAndaddOptionToSelect(index);
}

function enableDateCodeField( index )
{       
    var form = document.finalInventoryForm;
    
    if( form.dateCode[index].value == '0' )
    {
        form.dateCode1[index].style.display = 'block';
    }
    else
    {
       form.dateCode1[index].style.display = 'none';
    }

}
</SCRIPT>
<BODY bgcolor="ffffff" marginheight="0" marginwidth="0" topmargin=0 leftmargin=0>

<%
    if ( closeWindowAfterSessionTimeOut == null )
    {
%>
<table align="center" border="0" width="75%" bordercolor="#FFFFFF">

<html:form name="finalInventoryForm" type="com.scalar.chiptrack.ChipTrackActionForm" method="post" action="/finalInventory.do?action=save">

	<%

		if ( !user1.isActionAllowed ( Functionality.PACKING_SLIP, User.USER_ACTION_MODIFY  )  )
		{
	%>
	<%
			if ((viewOnly) || (finalInventoryDataList == null) || (finalInventoryDataList.isEmpty() == true))
			{
	%>
	<%		}
			else
			{
	%>
	<tr>
        <%
    if( ConfigManager.getShowFabLotNumberInPackingSlip() )
    {
    %>
        <td colspan='<%if (viewOnly) out.print ("7"); else out.print("8");%>'><font class='NArialS'><font color='blue'><b><%=Constants.NO_MODIFY_RIGHTS %></b></font>
		</td>
    <%
    }
    else
    {
    %>
        <td colspan='<%if (viewOnly) out.print ("6"); else out.print("7");%>'><font class='NArialS'><font color='blue'><b><%=Constants.NO_MODIFY_RIGHTS %></b></font>
            </td>
    <%}%>
    </tr>
	<%
			}
		}
	%>

	<input type="hidden" name="lineItemId" value='<%=request.getAttribute ("lineItemId")%>'/>
	<input type="hidden" name="fieldName" value='<%=request.getParameter ("fieldName")%>'/>
	<input type="hidden" name="fieldName1" value='<%=request.getParameter ("fieldName1")%>'/>
	<input type="hidden" name="actualCsLineItemId" value='<%=request.getParameter ("csLineItemId")%>'/>
	<input type="hidden" name="dropShip" value='<%=request.getParameter ("dropShip")%>'/>
    <%
    if( ConfigManager.getShowFabLotNumberInPackingSlip() )
    {
    %>

    <tr><td colspan='<%if (viewOnly) out.print ("7"); else out.print("8");%>'><chiptrack:errors styleClass="NArialL"/></td></tr>
    <tr><td colspan='<%if (viewOnly) out.print ("7"); else out.print("8");%>'><INPUT align=left border=0 maxLength=100 name="txtErrMsg" size=100 style="BORDER-BOTTOM: thin; BORDER-LEFT-STYLE: none; BORDER-RIGHT-STYLE: none; BORDER-TOP: thin; CLEAR: none; COLOR: red;font-family: arial;font-size: 10pt;font-weight:bold " value="" readOnly></td></tr>
    <tr><td colspan='<%if (viewOnly) out.print ("7"); else out.print("8");%>'><img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=5></td></tr>
    <tr><td colspan='<%if (viewOnly) out.print ("7"); else out.print("8");%>' align='center'><font class="NArialL">Inventory Selection Screen</font></td></tr>
    <tr><td colspan='<%if (viewOnly) out.print ("7"); else out.print("8");%>'><img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=5></td></tr>
    <%
    }
    else
    {
    %>
    <tr><td colspan='<%if (viewOnly) out.print ("6"); else out.print("7");%>'><chiptrack:errors styleClass="NArialL"/></td></tr>
    <tr><td colspan='<%if (viewOnly) out.print ("6"); else out.print("7");%>'><INPUT align=left border=0 maxLength=100 name="txtErrMsg" size=100 style="BORDER-BOTTOM: thin; BORDER-LEFT-STYLE: none; BORDER-RIGHT-STYLE: none; BORDER-TOP: thin; CLEAR: none; COLOR: red;font-family: arial;font-size: 10pt;font-weight:bold " value="" readOnly></td></tr>
    <tr><td colspan='<%if (viewOnly) out.print ("6"); else out.print("7");%>'><img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=5></td></tr>
    <tr><td colspan='<%if (viewOnly) out.print ("6"); else out.print("7");%>' align='center'><font class="NArialL">Inventory Selection Screen</font></td></tr>
    <tr><td colspan='<%if (viewOnly) out.print ("6"); else out.print("7");%>'><img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=5></td></tr>
    <%
        }
    %>

	<tr>
		<td align="center" bgcolor="#993333" width="20%" class="NArialL"><font color="#FFFFFF"><bean:message key="label.mfgPartNumber"/></font></td>
        <td align="center" bgcolor="#993333" width="15%" class="NArialL"><font color="#FFFFFF">Lot No</font></td>
		 <%
        if( ConfigManager.getShowFabLotNumberInPackingSlip() )
        {
        %>
        <td align="center" bgcolor="#993333" width="15%" class="NArialL"><font color="#FFFFFF">Fab Lot No</font></td>
        <%}%>
        <td align="center" bgcolor="#993333" width="15%" class="NArialL"><font color="#FFFFFF">Date Code</font></td>
		<td align="center" bgcolor="#993333" width="15%" class="NArialL"><font color="#FFFFFF">Date In</font></td>
		<td align="center" bgcolor="#993333" width="10%" class="NArialL"><font color="#FFFFFF">Quantity In</font></td>
		<%
			if (!viewOnly)
			{
		%>
		<td align="center" bgcolor="#993333" width="10%" class="NArialL"><font color="#FFFFFF">Balance</font></td>
		<%
			}
		%>
		<td align="center" bgcolor="#993333" width="15%" class="NArialL"><font color="#FFFFFF"><%if (viewOnly) out.print ("Qty Pulled"); else out.print ("Quantity to pull");%></font></td>
    </tr>
		<%
			int totalQtyPull = 0;
			if ((finalInventoryDataList == null) || (finalInventoryDataList.isEmpty() == true))
			{
				if( request.getParameter ("dropShip").equalsIgnoreCase( "true" ) )
				{
		%>
	<tr><td colspan='7'><FONT id="font1"></FONT></TD></TR>
	<tr>
		<td colspan="5">&nbsp</td>
        <td  colspan="2" align="center">
            <font class='NArialL'>
                <a href="javascript:addMore('<%=request.getParameter ("partNumber")%>', '<%=request.getParameter ("shippingFromAddressId")%>', '<%=request.getParameter ("csLineItemId")%>');">Click here to add new Lot</a>
            </font>
       </td>
	</tr>
	<input type="hidden" name="noOfLots" value='0'/>
	<tr>
		<td colspan=2 align='right'><font class='NArialL'>Total Quantity to be Shipped:</font></td>
		<td><input type="text" size='4' name="qtyTobeShipped" class='NArialL' style="BORDER-BOTTOM: thin; BORDER-LEFT-STYLE: none; BORDER-RIGHT-STYLE: none; BORDER-TOP: thin; CLEAR: none; COLOR: red;font-family: arial;font-size: 10pt;font-weight:bold " value='<%if (viewOnly) out.print (quantityToBeShipped); else out.print("");%>' readOnly disabled>
        <%
				if (!viewOnly)
				{
		%>	<script>calcDynValues();</script>
		<%
				}
		%>
		</td>
		<td colspan='<%if (viewOnly) out.print ("1"); else out.print("2");%>'  align='right'><font class='NArialL'>Total Quantity Pulled:&nbsp;&nbsp;</font></td>
		<td><input type="text" size='4' name="totals" class='NArialL' style="BORDER-BOTTOM: thin; BORDER-LEFT-STYLE: none; BORDER-RIGHT-STYLE: none; BORDER-TOP: thin; CLEAR: none; COLOR: red;font-family: arial;font-size: 10pt;font-weight:bold " value="" readOnly disabled><script>document.finalInventoryForm.totals.value='<%=totalQtyPull%>'</script></td>
	</tr>
	<tr><td colspan='<%if (viewOnly) out.print ("6"); else out.print("7");%>'><img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=30></td>
	</tr>

		<%
				}
				else
				{
		%>
    <tr><td colspan='<%if (viewOnly) out.print ("6"); else out.print("7");%>' align=center bgcolor='DEE1E2'><font class="NArialL"><font color="#000000">No Records Found</font></font></td></tr>
		<%
				}
			}
	        else
			{
				int size = finalInventoryDataList.size();
				FinalInventoryData finalInventoryData = null;

				String color[]		= {"DEE1E2", "FFFFEE"};
				int quantityShipped = 0;
				String processStepName = "";
				String partNumber	= "";
				String vendorName	= "";
                ArrayList dateCodeList = null;
				for ( int i = 0; i < size; i++ )
				{
					finalInventoryData = (FinalInventoryData) finalInventoryDataList.get(i);
					if( ( viewOnly ) && ( finalInventoryData.getQuantityPull() <= 0 ) )
					{
						continue;
					}

					if ( ((processStepName != null) && (processStepName.equalsIgnoreCase (finalInventoryData.getStepName()) == false)) ||
						((vendorName != null) && (vendorName.equalsIgnoreCase (finalInventoryData.getVendorLocation()) == false)))
					{
						processStepName = finalInventoryData.getStepName();
						partNumber = finalInventoryData.getMktPartNumber();
						vendorName = finalInventoryData.getVendorLocation();
                        dateCodeList = finalInventoryData.getDateCodeList();
                %>
            <tr><td colspan='<%if (viewOnly) out.print ("6"); else out.print("7");%>'>&nbsp;</td></tr>
            <tr>
                 <%if ( ConfigManager.getShowFabLotNumberInPackingSlip() ){%>
                    <td colspan='<%if (viewOnly) out.print ("7"); else out.print("8");%>' bgcolor="#999CCC" align='left'><font class='NArialL'><font color='#000000'>&nbsp;&nbsp;&nbsp;
                 <% } else{%>
                    <td colspan='<%if (viewOnly) out.print ("6"); else out.print("7");%>' bgcolor="#999CCC" align='left'><font class='NArialL'><font color='#000000'>&nbsp;&nbsp;&nbsp;
                 <%}%>
                        <%=processStepName + " - " + vendorName%>
                    </font></font>
                </td>
            </tr>
    		<%}%>
	    <tr bgcolor='<%=color[i%2]%>'>
		    <td align="center" nowrap width="20%"><font class="NArialL">
			    <%=finalInventoryData.getMktPartNumber()%></font>
                <input type="hidden" name="shippedPartNo" value='<%=finalInventoryData.getMktPartNumber()%>'>
		    </td>

		<input type="hidden" name="mktPartNumber" value='<%=finalInventoryData.getMktPartNumber()%>'>
		<input type="hidden" name="locationId" value='<%=finalInventoryData.getLocationId()%>'>
                <%
                if( ConfigManager.getShowFabLotNumberInPackingSlip() )
                {
                %>
                <td align="center" nowrap width="15%">

                    <%  if( finalInventoryData.getLotId() == -1 )
                        {
                    %>
                        <input type="text" name="fabLotNumber" size="13" maxLength="50" class="valuetxfield" value='<%=finalInventoryData.getFabLotNumber()%>'>
                    <%
                        }
                        else
                        {
                    %>
                        <font class="NArialL">
                        <%=finalInventoryData.getFabLotNumber()%>
                        </font>
                        <input type="hidden" name="fabLotNumber" value='<%= java.net.URLEncoder.encode( finalInventoryData.getFabLotNumber() , "UTF-8" ).replaceAll( "%27", "\\\\'" ).replaceAll( "\"", "\\\\\"") %>'>
                    <%
                        }
                    %>
                </td>
                <%
                    }
                    else
                    {
                %>

                    <input type="hidden" name="fabLotNumber" value='<%= java.net.URLEncoder.encode( finalInventoryData.getFabLotNumber() , "UTF-8" ).replaceAll( "%27", "\\\\'" ).replaceAll( "\"", "\\\\\"") %>'>
                <%
                    }
                %>
		<td align="center" nowrap width="15%">

			<%  if( finalInventoryData.getLotId() == -1 )
				{
			%>
				<input type="text" name="lotNumber" size="13" maxLength="50" class="valuetxfield" value='<%=finalInventoryData.getLotNumber()%>'>
			<%
				}
				else
				{
			%>
				<a href="javascript:openAudit('<%= java.net.URLEncoder.encode( finalInventoryData.getLotNumber() , "UTF-8" ).replaceAll( "%27", "\\\\'" ).replaceAll( "\"", "\\\\\"") %>','<%=finalInventoryData.getLotId()%>')" title='Click here for <%=finalInventoryData.getLotNumber()%> Lot Audit Information' onmouseover="window.status='Click here to Lot Audit Information';return true" onmouseout ="window.status='';return true"><font class="NArialL">
				<%=finalInventoryData.getLotNumber()%>
				</font></a>
				<input type="hidden" name="lotNumber" value='<%= java.net.URLEncoder.encode( finalInventoryData.getLotNumber() , "UTF-8" ).replaceAll( "%27", "\\\\'" ).replaceAll( "\"", "\\\\\"") %>'>
			<%
				}
			%>


		</td>
       
        <input type="hidden" name="lotId" value='<%=finalInventoryData.getLotId()%>'>
        <%
            String dateCode = "enableDateCodeField('" + i + "')";
			String dateCodevalue = finalInventoryData.getDateCode();

			//WorkWeek wk = WorkWeek.getCurrentWorkWeekInstance();
			//String currentDateCode = (wk.getWorkWeekYear() + "").substring(2) + wk.getCurrentWWNumber()+"";
			//String currentDateCode1 = (wk.getWorkWeekYear() + "").substring(2) + (wk.getCurrentWWNumber()-1)+"";
			//String currentDateCode2 = (wk.getWorkWeekYear() + "").substring(2) + (wk.getCurrentWWNumber()-2)+"";
        %>
		<td align="center" nowrap width="15%">
			<font class="NArialL">
			<%  if( finalInventoryData.getLotId() == -1 )
				{

			%>
				<input name="dateCode" maxLength="10" size="13" class="valuetxfield" value='<%=finalInventoryData.getDateCode()%>'>
			<%
				}
				else
				{
            %>
				<%--<%=finalInventoryData.getDateCode()%>--%>
                <input type="text" style="display:none;" name="dateCode1" class="txfield" size="12" maxlength="20"/>
				<input type="text" class="valuetxfield" name="dateCode" value='<%=finalInventoryData.getDateCode()%>'>
			<%
				}
			%>
			</font>
		</td>

		<td align="right" nowrap width="15%">
			<font class="NArialL">
			<%  if( finalInventoryData.getLotId() == -1 )
				{
					if( finalInventoryData.getDateIn() == null || ( ( StringUtils.formatDateToString (finalInventoryData.getDateIn())).equalsIgnoreCase("null") ) )
					{
			%>
					<input type="text" name="dateIn" maxLength="10" size="13" class="valuetxfield" value=''>
			<%
					}
					else
					{
			%>
					<input type="text" name="dateIn" maxLength="10" size="13" class="valuetxfield" value='<%=StringUtils.formatDateToString (finalInventoryData.getDateIn())%>'>
			<%		}
				}
				else
				{
					if( finalInventoryData.getDateIn() != null )
					{
			%>
				<%=StringUtils.formatDateToString (finalInventoryData.getDateIn())%>
			<%		}%>
				<input type="hidden" name="dateIn" value='<%=finalInventoryData.getDateIn()%>'>
			<%
				}
			%>
			</font>
		</td>

		<td align="right" nowrap width="10%">
			<font class="NArialL">
			<%  if( finalInventoryData.getLotId() == -1 )
				{
			%>
				<input type="text" name="hdnQuantityIn" maxLength="10" size="13" class="valuetxfield" value='<%=finalInventoryData.getQuantityIn()%>' onkeypress="javascript:numericFieldKeyPress( this )" onblur="setQuantyties(<%=i%>)">
			<%
				}
				else
				{
			%>
				<%=StringUtils.formatUnits (finalInventoryData.getQuantityIn())%>
				<input type="hidden" name="hdnQuantityIn" value='<%=finalInventoryData.getQuantityIn()%>'>
			<%
				}
			%>
			</font>

		</td>

		<%
					if (!viewOnly)
					{
		%>
		<td align="right" nowrap width="10%"><font class="NArialL">
			<input type=hidden name=initBalances value='<%=finalInventoryData.getBalance()%>' >
			<input type="text" size=6 align=right name="balance" class='valuetxfield' style="BORDER-BOTTOM: thin; BORDER-LEFT-STYLE: none; BORDER-RIGHT-STYLE: none; BORDER-TOP: thin; CLEAR: none; COLOR: red;font-family: arial;font-size: 10pt;font-weight:bold " readOnly disabled value='<%/*finalInventoryData.getBalance()*/%>'>
		</td>
		<%
					}
		%>

		<td align="center" nowrap width="15%"><font class="NArialL">
        <%
                    String qtyToPull = "";

                    if ( finalInventoryData.getQuantityPull() > 0 )
                    {
                        qtyToPull = finalInventoryData.getQuantityPull()+"";
                        totalQtyPull += finalInventoryData.getQuantityPull();
                    }

		%>

        <%			if (viewOnly)
                    {
                        out.print ( ( StringUtils.formatUnits( qtyToPull ) == null ) ? "" : StringUtils.formatUnits( qtyToPull ) );
                    }
                    else
                    {
                        if ( finalInventoryData.getIsHold() == 0 )
                        {
		%>
			<input type="text" nowrap name="quantityToPull" onfocus="javascript:holdLotInfo()"  onblur="javascript:clearHoldLotInfo()" value='<%=qtyToPull%>' class='valuetxfield' readonly></font>
        <%              } else { %>
            <input type="text" nowrap name="quantityToPull" onkeyup='addQuantity(<%=i%>)' onkeypress="javascript:numericFieldKeyPress( this )" value='<%=qtyToPull%>' class='valuetxfield'></font>
       <%               } %>
			<input type="hidden" name="quantityToPullHidden" value='<%=qtyToPull%>'>
			<input type="hidden" name="csLineItemId" value='<%=finalInventoryData.getCsLineItemId()%>'/>
		</td>
        <%
					}
		%>
	</tr>
        <%
				} // for loop ends here
        %>
	<input type="hidden" name="noOfLots" value='<%=size++%>'/>
	<tr><td colspan='7'><FONT id="font1"></FONT></TD></TR>
	<!--<tr>
		<td colspan="6">&nbsp</td>
        <td align="center"><a href="javascript:addMore(' < % = finalInventoryData.getMktPartNumber() % >');"><img src="< % = chipTracContext % >/jsp/includes/images/addmore.gif" border=0></a></td>
	</tr>  -->
	<%
		if( ( new Boolean( request.getParameter( "dropShip" ) ) ).booleanValue() )
		{
			if( !request.getParameter( "viewonly" ).equalsIgnoreCase( "true" ) )
			{
	%>
	<tr>
		<td colspan="5">&nbsp</td>
        <td  colspan="2" align="center">
            <font class='NArialL'>
                <a href="javascript:addMore('<%=finalInventoryData.getMktPartNumber()%>', '<%=request.getParameter ("shippingFromAddressId")%>', '<%=finalInventoryData.getCsLineItemId()%>');">Click here to add new Lot</a>
            </font>
        </td>
	</tr>
	<%
			}
		}
	%>
	<tr><td colspan='<%if (viewOnly) out.print ("6"); else out.print("7");%>'><img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=20></td></tr>

	<tr>
		<td colspan=2 align='right'><font class='NArialL'>Total Quantity to be Shipped:</font></td>
		<td><input type="text" size='4' name="qtyTobeShipped" class='NArialL' style="BORDER-BOTTOM: thin; BORDER-LEFT-STYLE: none; BORDER-RIGHT-STYLE: none; BORDER-TOP: thin; CLEAR: none; COLOR: red;font-family: arial;font-size: 10pt;font-weight:bold " value='<%if (viewOnly) out.print (quantityToBeShipped); else out.print("");%>' readOnly disabled>
        <%
				if (!viewOnly)
				{
		%>	<script>calcDynValues();</script>
		<%
				}
		%>
		</td>
		<td colspan='<%if (viewOnly) out.print ("1"); else out.print("2");%>'  align='right'><font class='NArialL'>Total Quantity Pulled:&nbsp;&nbsp;</font></td>
		<td><input type="text" size='4' name="totals" class='NArialL' style="BORDER-BOTTOM: thin; BORDER-LEFT-STYLE: none; BORDER-RIGHT-STYLE: none; BORDER-TOP: thin; CLEAR: none; COLOR: red;font-family: arial;font-size: 10pt;font-weight:bold " value="" readOnly disabled><script>document.finalInventoryForm.totals.value='<%=totalQtyPull%>'</script></td>
	</tr>
	<tr><td colspan='<%if (viewOnly) out.print ("6"); else out.print("7");%>'><img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=30></td></tr>

		<%
			}
		%>

	<tr>
		<td colspan='<%if (viewOnly) out.print ("6"); else out.print("7");%>' align=center>
		<%
			if ( ( viewOnly ) || ( finalInventoryDataList == null ) || ( ( finalInventoryDataList.isEmpty() == true ) &&  request.getParameter( "dropShip" ).equalsIgnoreCase( "false" ) ) )
			{
		%>
			<a href="javascript:close()"><font class='NArialL'>[Close this window]</font></a>
		<%
			}
			else
			{
		%>
			<chiptrack:restrictedLink functionality='<%=Functionality.PACKING_SLIP%>' action='<%=User.USER_ACTION_MODIFY%>' href='javascript:window.saveData()' onmouseover="window.status='Click here to save';return true" onmouseout ="window.status='';return true"> <img border="0" src="<%=chipTracContext%>/jsp/includes/images/save.gif" width="53" height="17"></chiptrack:restrictedLink>
			&nbsp;&nbsp;&nbsp;
			<a href="javascript:resetValues()" onmouseover="window.status='Click here to reset values';return true" onmouseout ="window.status='';return true" title='Click here to reset all field values'><img border="0" src="<%=chipTracContext%>/jsp/includes/images/reset.gif" width="53" height="17"></a>&nbsp;&nbsp;&nbsp;
			<a href="javascript:close()" onmouseover="window.status='Click here to close';return true" onmouseout ="window.status='';return true" title='Click here to close the window'><img border="0" src="<%=chipTracContext%>/jsp/includes/images/cancel.gif" width="53" height="17"></a>
		<%
        }
		%>
		</td>
	</tr>

	<tr><td colspan='<%if (viewOnly) out.print ("6"); else out.print("7");%>'><img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=30></td></tr>
</html:form>
</table>

<% } else { %>
    <table cellpadding='0' cellspacing='0' bgcolor='FDF5E6' border="0" width="100%"  height="100%" align=center>
        <tr>
            <td>
                <table align="center" border="0" width="40%" bgcolor="#FDF5E6">
                    <tr><td>&nbsp;</td></tr>
                    <tr><td align="center" ><font class="NArialL" ><font color="red">Session has been time out , Please close this window and login again.</font></font></td></tr>
                    <tr><td>&nbsp;</td></tr>
                    <tr><td align="center" ><a href="javascript:window.close();" title='Click here to close the window'><font class='NArialL'>[Close this window]</font></a></td></tr>
                </table>
            </td>
       </tr>
       <tr><td>&nbsp;</td></tr>
    </table>
<% } %>
</body>
</html:html>